import User.*;
import zy.Cust;
import zy.Dish;
import zy.Warehouse;

import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

/*
 *@Student 张策
 */
public class Main {
    public static boolean F_id(){//厨师登录的方法
        String ID = "qidian";//厨师ID
        String PASSWORD = "123456";//厨师密码
        int choice=3;//输入机会
        int sleepTime=5000;//睡眠时间
        Scanner scanner=new Scanner(System.in);
        System.out.println("注意你有三次登录账号的机会！");
        String id;
        String passWord;
        while (true) {
            System.out.print("请输入账号：");
            id=scanner.nextLine();
            System.out.print("请输入密码：");
            passWord=scanner.nextLine();
            if(id.equals(ID)&&passWord.equals(PASSWORD)){
                return true;
            }else {
                choice--;
                System.out.println("账号密码输入错误你还有"+choice+"次机会");
            }
            if(choice<=0){
                System.out.println("机会用尽，"+sleepTime/1000+"秒后重新进入系统");
                try {
                    for (int i = 5; i > 0; i--) {
                        System.out.println(i);
                        Thread.sleep(sleepTime/5);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }finally {
                    return false;
                }
            }
        }
    }
    public static Cust custcreat(Warehouse warehouse){
        System.out.println("请输入您的用户名");
        Scanner scanner=new Scanner(System.in);
        int size = warehouse.custs.size();
        String name=scanner.nextLine();
        for (int i = 0; i < size; i++) {
            if(warehouse.custs.get(i).getName().equals(name)){
                if(warehouse.custs.get(i).getVIP().equals("VIP用户")){
                    System.out.println("欢迎VIP用户的到来");
                }else {
                    System.out.println("欢迎老顾客");
                }
                return warehouse.custs.get(i);
            }
        }
        Cust cust = new Cust(name);
        warehouse.custs.add(cust);
        return cust;
    }
    public static int login(Warehouse warehouse){//角色选择
        System.out.println("欢迎来到起点炒个菜，请选择你的身份：");
        System.out.println("1:厨师  2:顾客  3:退出");
        Scanner scanner=new Scanner(System.in);
        while (true){
            String ros  = scanner.nextLine();
            while (!warehouse.isNum(ros)){
                ros=scanner.nextLine();
            }
            int rose=Integer.parseInt(ros);
            if(rose==1){
//            boolean bool = F_id();//厨师账号登录
//                while (!bool){
//                    bool = F_id();
//                }
            boolean bool=true;
            if(bool){
                System.out.println("登入成功，欢迎大厨！");
                return 1;
            }
        }else if(rose==2){
            return 2;
        }else if(rose==3){
            return 0;
        }else {
            System.out.println("输入错误请再次输入");
        }
        }
    }
    public static void ChefL(Warehouse warehouse){
        boolean pos=true;
        Chef chef = new Chef();
        while (pos){
        int menu = chef.menu();
        if(menu==6){
            return;
        }
        chef.doOperation(menu,warehouse);
        }
    }
    public static void Customer(Warehouse warehouse){
        Cust cust = custcreat(warehouse);
        boolean pos=true;
        Customer customer = new Customer();
        while (pos){
            int menu = customer.menu();
            if(menu==6){
                return ;
            }
            customer.doOperation(menu,warehouse,cust);
        }
    }
    public static void main(String[] args) {
        Warehouse warehouse = new Warehouse();
        boolean pos=true;
        while (pos){
        int login = login(warehouse);
        switch (login){
            case 1:
                ChefL(warehouse);
                break;
            case 2:
                Customer(warehouse);
                break;
            case 0:
                System.exit(0);
            default:break;
        }
        }
    }
}